package core

import (
	"github.com/google/uuid"
	"strings"
)

/**
 *    Description: 随机唯一ID
 *    Date: 2024/3/18
 */

// KisID 获取一个中随机实例ID
// 格式为  "prefix1-[prefix2-][prefix3-]ID"
// 如：flow-1234567890
// 如：func-1234567890
// 如: conn-1234567890
// 如: func-1-1234567890

func KisID(prefix ...string) (kisID string) {
	idStr := strings.Replace(uuid.New().String(), "-", "", -1)
	kisID = formatKisID(idStr, prefix...)
	return
}

func formatKisID(idStr string, prefix ...string) string {
	var kisID string
	for _, fix := range prefix {
		kisID += fix
		kisID += "-"
	}
	return kisID + idStr
}
